package com.symc.his.api.impl.doctor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.symc.his.api.base.BaseApiService;
import com.symc.his.api.base.BaseResponse;
import com.symc.his.api.doctor.VisitRecordService;
import com.symc.his.api.doctor.dto.req.VisitRecordReqDTO;
import com.symc.his.api.doctor.dto.resp.VisitRecordRespDTO;
import com.symc.his.api.impl.entity.VisitRecordDO;
import com.symc.his.api.impl.feign.PatientServiceFeign;
import com.symc.his.api.impl.mapper.VisitRecordMapper;
import com.symc.his.api.patient.dto.resp.PatientInfoRespDTO;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @CreateTime: 2023/4/12 21:07
 * @Version:
 * @Since: 1.8
 * @Author: 辛凤文 forward.seen@foxmail.com
 */
@RestController
public class VisitRecordServiceServiceImpl extends BaseApiService implements VisitRecordService {
    @Resource
    private VisitRecordMapper visitRecordMapper;

    @Resource
    private PatientServiceFeign patientServiceFeign;

    @Override public BaseResponse<VisitRecordRespDTO> getVisitRecordList() {
        LambdaQueryWrapper<VisitRecordDO> queryWrapper = new LambdaQueryWrapper<VisitRecordDO>();
        List<VisitRecordDO> records = visitRecordMapper.selectList(queryWrapper);
        VisitRecordRespDTO visitRecordList = DO2DTO(records, VisitRecordRespDTO.class);
        return setResultSuccess(visitRecordList);
    }

    @Override
    public BaseResponse<VisitRecordRespDTO> getVisitRecordForDoctorList(Integer currentPageNum, Integer pageSize,
        VisitRecordReqDTO visitRecordReqDTO) {
        String doctorCode = visitRecordReqDTO.getRecDoctorCode();
        String deptCode = visitRecordReqDTO.getRecDeptCode();
        Page<VisitRecordDO> page = new Page<>(currentPageNum, pageSize);
        LambdaQueryWrapper<VisitRecordDO> queryWrapper = new LambdaQueryWrapper<VisitRecordDO>()
            .eq(!StringUtils.isEmpty(doctorCode),VisitRecordDO::getRecDoctorCode, doctorCode)
            .eq(!StringUtils.isEmpty(deptCode),VisitRecordDO::getRecDeptCode,deptCode);
        Page<VisitRecordDO> currentPage = visitRecordMapper.selectCurrentPage(page, queryWrapper);
        return setResultSuccess(currentPage);
    }

    @Override public BaseResponse<VisitRecordRespDTO> getPatientInfoByVisitRecordId(Integer visitRecordId) {
        VisitRecordDO visitRecordDO = visitRecordMapper.selectById(visitRecordId);
        String patientId = visitRecordDO.getPatientId();
        BaseResponse<PatientInfoRespDTO> patientInfo = patientServiceFeign.getPatientInfoByPatientId(patientId);
        return setResultSuccess(patientInfo);
    }

}